package com.mall.server.controller.oms;

import com.mall.model.domain.OmsOrderReturnReason;
import com.mall.model.vo.CommonPage;
import com.mall.model.vo.CommonResult;
import com.mall.server.service.oms.OmsOrderReturnReasonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : xyiaao
 * @createDate : 2022/4/3 9:25
 */
@CrossOrigin
@RestController
@RequestMapping("/returnReason")
public class OmsOrderReturnReasonController {

    @Autowired
    private OmsOrderReturnReasonService omsOrderReturnReasonService;


    /**
     * 添加退货原因
     *
     * @param omsOrderReturnReason
     * @return
     */
    @PostMapping("/create")
    public CommonResult create(@RequestBody OmsOrderReturnReason omsOrderReturnReason) {

        omsOrderReturnReasonService.create(omsOrderReturnReason);
        return CommonResult.success();
    }


    /**
     * 批量删除退货原因
     *
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public CommonResult delete(@RequestParam List<Long> ids) {

        omsOrderReturnReasonService.delete(ids);
        return CommonResult.success();
    }


    /**
     * 分页查询退货原因
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    public CommonResult list(Integer pageNum, Integer pageSize) {

        CommonPage<OmsOrderReturnReason> page = omsOrderReturnReasonService.page(pageNum, pageSize);
        return CommonResult.success(page);
    }


    /**
     * 修改退货原因启用状态
     *
     * @param ids
     * @param status
     * @return
     */
    @PostMapping("/update/status")
    public CommonResult updateStatus(@RequestParam List<Long> ids, Integer status) {

        omsOrderReturnReasonService.updateStatus(ids, status);
        return CommonResult.success();
    }


    /**
     * 修改退货原因
     *
     * @param id
     * @param omsOrderReturnReason
     * @return
     */
    @PostMapping("/update/{id}")
    public CommonResult update(@PathVariable("id") Long id, @RequestBody OmsOrderReturnReason omsOrderReturnReason) {

        omsOrderReturnReasonService.update(id, omsOrderReturnReason);
        return CommonResult.success();
    }


    /**
     * 获取单个退货原因详情信息
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public CommonResult get(@PathVariable("id") Long id) {

        OmsOrderReturnReason omsOrderReturnReason = omsOrderReturnReasonService.getById(id);
        return CommonResult.success(omsOrderReturnReason);
    }

}
